<template>
  <div class="home">
     <el-dialog
    title="发布公告"
    :visible.sync="addUserDia"
    width="70%"
    center
    >
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm"  class="demo-ruleForm">
     <div class="header">
       <el-form-item prop="inviteTitle" verify>
       <el-input v-model="ruleForm.inviteTitle" placeholder="请输入标题" ></el-input>
       </el-form-item>
    </div>
    <div class="edits">
    <mavon-editor v-model="ruleForm.inviteContent" 
    @change="changeData" class="nossr" 
    :toolbarsBackground="'#cccccc'"
    :previewBackground="'#fbfbfb'"
    :scrollStyle="true"/>
    </div>
    <div class="footer">
       <el-form-item prop="type" verify>
      <el-select v-model="ruleForm.type" placeholder="请选择分类">
      <el-option label="问题" value="问题"></el-option>
      <el-option label="帖子" value="帖子"></el-option>
      <el-option label="分享" value="分享"></el-option>
      <el-option label="思绪" value="思绪"></el-option>
      </el-select>
       </el-form-item>
      <el-button type="success" @click="okbtn">发布</el-button>
      <el-button type="primary" @click="quxiao">取消</el-button>
      
    </div>
    </el-form>
  </el-dialog>
  </div>
</template>

<script>
import {updateInvite} from '@/api/shop'
export default {
  name: 'addUser',

  data () {
    return {
      ruleForm:{
      inviteTitle:'',
      type:'',
      inviteContent:''
      },
        addUserDia:false,
        texts:'',
        inviteCode:''
    }
  },

  methods: {
    open(flag,val) {
      this.inviteCode=val.inviteCode;
      this.ruleForm=val
      this.addUserDia = flag;
    },quxiao(){
      this.addUserDia=false
    },okbtn(){
       let obj={
        "inviteContent":this.texts,
        "inviteTitle": this.ruleForm.inviteTitle,
        "type":this.ruleForm.type,
        "inviteCode":this.inviteCode
          }
      updateInvite(obj).then(response => {     
        if(response.data.responseCode===200){
        this.$message({
          showClose: true,
          message: '恭喜你，修改成功！',
          type: 'success'
        });
        this.$emit('getData');
        this.addUserDia=false;
        }
      }).catch(error=>{
           this.$message({
          showClose: true,
          message: '错了哦，新增失败！',
          type: 'error'
        });
      })
    },
     changeData(value, render) {
            this.inviteContent = render;
            this.texts=render;
        },
  }
}
</script>

<style scoped>
.home{
  width: 100%;
  margin: 0 auto;
}
.edits{
  width: 100%;
  height: 300px;
   margin: 0 auto;
}

.header{
  width: 95%;
  background: rgb(195, 225, 233);
   margin: 0 auto;
}
.header .el-input{
  width: 100%;
  font-size: 26px;
  height: 10%;
  padding: 3px;
}
.footer{
  width: 100%;
  padding-top: 20px;
  text-align: right;
}
</style>
<style>
.nossr{
    position: absolute;
    width: 95%; 
    height: 300px;
   margin: 0 auto;

}
</style>
